﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace TestConsole
{
    public abstract class BaseClient
    {
        protected readonly HttpClient httpClient;
        public BaseClient(HttpClient httpClient)
        {
            this.httpClient = httpClient;
        }

        public virtual async Task<string> SendRequestAsync(Action<HttpRequestMessage> reqAction = null)
        {


            using (var client = new HttpClient())
            {

                httpClient.BaseAddress = new Uri("http://localhost:5003");
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // I would normally use httpClient.DeleteAsync but I can't because I need to set content on the request.
                // For this reason I use httpClient.SendAsync where I can both specify the HTTP DELETE with a request body.
                var request = new HttpRequestMessage(HttpMethod.Get, "SampleTest/IncidentTest")
                {

                };

                var response = await httpClient.SendAsync(request);
                return await response.Content.ReadAsStringAsync();
            }
            using (this.httpClient)
            {

                //var response = await client.SendAsync(request);
                //var req = new HttpRequestMessage
                //    {
                //        Method = HttpMethod.Get
                //    };

                //    //reqAction?.Invoke(req);

                //    var response = await this.httpClient.SendAsync(req);

                //    if (response.IsSuccessStatusCode)
                //    {
                //        var result = await response.Content.ReadAsStringAsync();

                //        return result;
                //    }
                //    else
                //    {
                //        return await Task.FromResult(string.Empty);
                //    }
            }
        }
    }
}
